import 'package:enjoy_plus_three/pages/house/building_list.dart';
import 'package:enjoy_plus_three/pages/house/components/location_list.dart';
import 'package:enjoy_plus_three/pages/house/house_detail.dart';
import 'package:enjoy_plus_three/pages/house/house_form.dart';
import 'package:enjoy_plus_three/pages/house/house_list.dart';
import 'package:enjoy_plus_three/pages/house/room_list.dart';
import 'package:enjoy_plus_three/pages/login/index.dart';
import 'package:enjoy_plus_three/pages/notice/index.dart';
import 'package:enjoy_plus_three/pages/profile/index.dart';
import 'package:enjoy_plus_three/pages/tab_bar_page.dart';
import 'package:enjoy_plus_three/utils/token.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      theme: ThemeData(fontFamily: 'NotoSansSC'),
      routes: {
        '/': (context) => const TabBarPage(),
        '/detail': (context) => const NoticeDetail(),
        '/login': (context) => const LoginPage(),
        '/house_list':(context) => const HouseList()
      },
      onGenerateRoute: (settings) {
        final tokenManager = TokenManager();
        final token = tokenManager.getToken() ?? '';
        if (token.isEmpty && settings.name != '/login') {
          return MaterialPageRoute(builder: (context) => const LoginPage());
        }

        if (settings.name == '/profile') {
          return MaterialPageRoute(
            builder:
                (context) => ProfilePage(userInfo: settings.arguments as Map),
          );
        }

        // if (settings.name == '/house_list') {
        //   return MaterialPageRoute(builder: (context) => const HouseList());
        // }

        if (settings.name == '/location_list') {
          return MaterialPageRoute(builder: (context) => const LocationList());
        }

        if (settings.name == '/building_list') {
          debugPrint('楼栋传参 ${settings.arguments}');
          return MaterialPageRoute(
            builder:
                (context) =>
                    BuildingList(point: (settings.arguments as Map)['point']),
          );
        }

        if (settings.name == '/room_list') {
          Map temp = settings.arguments as Map;
          debugPrint('房间传参 ${temp}');
          return MaterialPageRoute(
            builder:
                (context) =>
                    RoomList(point: temp['point'], building: temp['building']),
          );
        }

        if (settings.name == '/house_form') {
          debugPrint('房间详情传参 ${settings.arguments}');
          return MaterialPageRoute(
            builder: (context) => HouseForm(params: settings.arguments as Map),
          );
        }

        if (settings.name == '/house_detail') {
          debugPrint('我的房屋详情传参 ${settings.arguments}');
          return MaterialPageRoute(
            builder: (context) => HouseDetail(id: (settings.arguments as Map)['id']),
          );
        }

        return null;
      },
      initialRoute: '/',
    ),
  );
}
